package cn.itheima.taotao.service.impl;

import cn.itheima.taotao.domain.DataGridResult;
import cn.itheima.taotao.domain.EasyUITreeNode;
import cn.itheima.taotao.domain.ItemCat;
import cn.itheima.taotao.domain.ItemCatExample;
import cn.itheima.taotao.mapper.ItemCatMapper;
import cn.itheima.taotao.service.ItemCatService;
import cn.itheima.taotao.service.ItemService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator .
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {

    @Resource
    private ItemCatMapper itemCatMapper;


    @Override
    public List<EasyUITreeNode> getItemCatList(Long parentId) {
        ItemCatExample itemCatExample = new ItemCatExample();
        ItemCatExample.Criteria criteria = itemCatExample.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<ItemCat> itemCats = itemCatMapper.selectByExample(itemCatExample);
        List<EasyUITreeNode> easyUITreeNodes = new ArrayList<EasyUITreeNode>();
        for (ItemCat itemCat : itemCats) {
            EasyUITreeNode easyUITreeNode = new EasyUITreeNode();
            easyUITreeNode.setId(itemCat.getId());
            easyUITreeNode.setText(itemCat.getName());
            easyUITreeNode.setState(itemCat.getIsParent() ? "closed" : "open");
            easyUITreeNodes.add(easyUITreeNode);
        }
        return easyUITreeNodes;
    }
}
